﻿using MediatR;
using Traceability_Management.Domain;
using Traceability_Management.ErrorCode;
using Traceability_Management.Infrastructure.Interfaces;
using Traceability_Management.Read.Api.Application.Command.Farmings_NextWay;
using Traceability_Management.Read.Api.Application.Command.SlaughtsWay_NextWay;

namespace Traceability_Management.Read.Api.Application.CommandHandler.SlaughtsWay_NextWay
{
    public class AddNextSlaughtsCommandHandler : IRequestHandler<AddNextSlaughtsCommand, ApiResult<int>>
    {
        IBaseReponsitory<Slaughts_Next> Slaughts_Next;

        public AddNextSlaughtsCommandHandler(IBaseReponsitory<Slaughts_Next> Slaughts_Next)
        {
            this.Slaughts_Next = Slaughts_Next;
        }

        public async Task<ApiResult<int>> Handle(AddNextSlaughtsCommand request, CancellationToken cancellationToken)
        {

            await Slaughts_Next.AddAsync(request.Slaughts_Next);
            return new ApiResult<int>
            {
                Code = ApiEnum.Success,
                Message = "添加成功",
                Data = 1
            };
        }
    }
}
